package com.jn.retrofit.views;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.jn.retrofit.R;
import com.jn.retrofit.base.BaseActivity;
import com.jn.retrofit.contract.TestContract;
import com.jn.retrofit.presenter.TestPresenter;

public class TestActivity extends BaseActivity
        implements TestContract.ITestView, View.OnClickListener {

   private TestContract.ITestPresenter mPresenter;
   private Button mButtonGet;
   private Button mButtonPost;
   private EditText mEdit;
   private TextView mText;

   @Override
   public int getLayoutId() {
      return R.layout.activity_test;
   }

   @Override
   public void init() {
      mPresenter = new TestPresenter(this, this);
      mButtonGet = findViewById(R.id.button_get);
      mButtonPost = findViewById(R.id.button_post);
      mEdit = findViewById(R.id.edit);
      mText = findViewById(R.id.text);
      mButtonGet.setOnClickListener(this);
      mButtonPost.setOnClickListener(this);
   }

   @Override
   public void onHttpLoading(boolean loading) {

   }

   @Override
   public void onHttpFail(String... msg) {

   }

   @Override
   public void onHttpTimeout() {

   }

   @Override
   public void onHttpTokenExpiration() {

   }

   @Override
   public void showData(String data) {
      mText.setText(data);
   }

   @Override
   public void onClick(View v) {
      int id = v.getId();
      String keyWord = mEdit.getText().toString();
      if (id == R.id.button_get) {
         //if (!TextUtils.isEmpty(keyWord)) {
            mPresenter.get(keyWord);
         //}
      } else if (id == R.id.button_post) {
         //if (!TextUtils.isEmpty(keyWord)) {
            mPresenter.post(keyWord);
         //}
      }
   }
}
